package com;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {

    public static void main(String[] args) {
        String s = "{\n" +
                "\t\"entities\": [{\n" +
                "\t\t\"entity_info\": {\n" +
                "\t\t\t\"uid\": \"1291933\",\n" +
                "\t\t\t\"list_name\": \"SDNLIST\",\n" +
                "\t\t\t\"entity_meta_info_attributes\": [{\n" +
                "\t\t\t\t\"attribute_name\": \"row_internal_id\",\n" +
                "\t\t\t\t\"attribute_values\": [\"87092138\"],\n" +
                "\t\t\t\t\"encrypted\": false,\n" +
                "\t\t\t\t\"encryption_type\": \"\"\n" +
                "\t\t\t}, {\n" +
                "\t\t\t\t\"attribute_name\": \"data_source_name\",\n" +
                "\t\t\t\t\"attribute_values\": [\"OFACRTS_TRANSACTION_DS\"],\n" +
                "\t\t\t\t\"encrypted\": false,\n" +
                "\t\t\t\t\"encryption_type\": \"\"\n" +
                "\t\t\t}, {\n" +
                "\t\t\t\t\"attribute_name\": \"check_definition_name\",\n" +
                "\t\t\t\t\"attribute_values\": [\"Transaction-SDN-Check\"],\n" +
                "\t\t\t\t\"encrypted\": false,\n" +
                "\t\t\t\t\"encryption_type\": \"\"\n" +
                "\t\t\t}]\n" +
                "\t\t},\n" +
                "\t\t\"entity_attributes\": [{\n" +
                "\t\t\t\"attribute_name\": \"pob\",\n" +
                "\t\t\t\"attribute_values\": [\"Leningrad, Russia\"],\n" +
                "\t\t\t\"encrypted\": false,\n" +
                "\t\t\t\"encryption_type\": \"\"\n" +
                "\t\t}, {\n" +
                "\t\t\t\"attribute_name\": \"dob\",\n" +
                "\t\t\t\"attribute_values\": [\"1965/09/07\"],\n" +
                "\t\t\t\"encrypted\": false,\n" +
                "\t\t\t\"encryption_type\": \"\"\n" +
                "\t\t}, {\n" +
                "\t\t\t\"attribute_name\": \"last_name\",\n" +
                "\t\t\t\"attribute_values\": [\"ZAYTSEV\"],\n" +
                "\t\t\t\"encrypted\": false,\n" +
                "\t\t\t\"encryption_type\": \"\"\n" +
                "\t\t}, {\n" +
                "\t\t\t\"attribute_name\": \"LIST_DEFINITION_ID\",\n" +
                "\t\t\t\"attribute_values\": [\"37312:35571:1020:12642:1003:34976:10793:35216\"],\n" +
                "\t\t\t\"encrypted\": false,\n" +
                "\t\t\t\"encryption_type\": \"\"\n" +
                "\t\t}, {\n" +
                "\t\t\t\"attribute_name\": \"first_name\",\n" +
                "\t\t\t\"attribute_values\": [\"Aleksey Alekseyevich\"],\n" +
                "\t\t\t\"encrypted\": false,\n" +
                "\t\t\t\"encryption_type\": \"\"\n" +
                "\t\t}, {\n" +
                "\t\t\t\"attribute_name\": \"worldcheck_category\",\n" +
                "\t\t\t\"attribute_values\": [\"CRIME - ORGANIZED\"],\n" +
                "\t\t\t\"encrypted\": false,\n" +
                "\t\t\t\"encryption_type\": \"\"\n" +
                "\t\t}]\n" +
                "\t}],\n" +
                "\t\"entity_hit_match\": [{\n" +
                "\t\t\"entity_info\": {\n" +
                "\t\t\t\"uid\": \"1291933\",\n" +
                "\t\t\t\"list_name\": \"SDNLIST\",\n" +
                "\t\t\t\"entity_meta_info_attributes\": [{\n" +
                "\t\t\t\t\"attribute_name\": \"row_internal_id\",\n" +
                "\t\t\t\t\"attribute_values\": [\"87092138\"],\n" +
                "\t\t\t\t\"encrypted\": false,\n" +
                "\t\t\t\t\"encryption_type\": \"\"\n" +
                "\t\t\t}, {\n" +
                "\t\t\t\t\"attribute_name\": \"data_source_name\",\n" +
                "\t\t\t\t\"attribute_values\": [\"OFACRTS_TRANSACTION_DS\"],\n" +
                "\t\t\t\t\"encrypted\": false,\n" +
                "\t\t\t\t\"encryption_type\": \"\"\n" +
                "\t\t\t}, {\n" +
                "\t\t\t\t\"attribute_name\": \"check_definition_name\",\n" +
                "\t\t\t\t\"attribute_values\": [\"Transaction-SDN-Check\"],\n" +
                "\t\t\t\t\"encrypted\": false,\n" +
                "\t\t\t\t\"encryption_type\": \"\"\n" +
                "\t\t\t}]\n" +
                "\t\t},\n" +
                "\t\t\"match_info\": [{\n" +
                "\t\t\t\"source_attribute_name\": \"transaction_shipping_country\",\n" +
                "\t\t\t\"source_attribute_value\": \"Russian Federation\",\n" +
                "\t\t\t\"entity_attribute_name\": \"transaction_shipping_country\",\n" +
                "\t\t\t\"entity_attribute_value\": \"Russian Federation\",\n" +
                "\t\t\t\"score\": \"1\",\n" +
                "\t\t\t\"match_type\": \"configuration.detection.check.match.type.exact.match\",\n" +
                "\t\t\t\"match_text\": \"RUSSIAN FEDERATION\",\n" +
                "\t\t\t\"match_attributes\": [],\n" +
                "\t\t\t\"hit_type\": \"TRANSACTION\"\n" +
                "\t\t}, {\n" +
                "\t\t\t\"source_attribute_name\": \"transaction_shipping_name\",\n" +
                "\t\t\t\"source_attribute_value\": \"Alexey Zaytsev\",\n" +
                "\t\t\t\"entity_attribute_name\": \"transaction_shipping_name\",\n" +
                "\t\t\t\"entity_attribute_value\": \"Alexey Zaytsev\",\n" +
                "\t\t\t\"score\": \"1\",\n" +
                "\t\t\t\"match_type\": \"configuration.detection.check.match.type.fuzzy.match.90\",\n" +
                "\t\t\t\"match_text\": \"ZAYTSEV Alexey\",\n" +
                "\t\t\t\"match_attributes\": [],\n" +
                "\t\t\t\"hit_type\": \"TRANSACTION\"\n" +
                "\t\t}]\n" +
                "\t}]\n" +
                "}\n" +
                "\n" +
                "\n" +
                "\n";
        // 把要匹配的字符串写成正则表达式，然后要提取的字符使用括号括起来
        // 在这里，我们要提取最后一个数字，正则规则就是“一个数字加上大于等于0个非数字再加上结束符”

//        String ss = "A876X";
//        Pattern pattern = Pattern.compile("\\{\"entities\": [.*$");
//        Matcher matcher = pattern.matcher(ss);
//        if(matcher.find())
//            System.out.println(matcher.group(1));


        String data = "{\"code\":1,\"msg\":\"操作成功!\",\"success\":true,\"data\":{\"code\":\"3100183130\",\"number\":\"39518133\",\"issue_date\":\"20190308\",\"amount\":\"339.62\"}}";
        List<String> failList = searchMatch(s,"match_info\":\"(\\w+)?\"",1);
        System.out.println(failList.toString());

    }

    public static List
            <String> searchMatch(String withinText, String regString,int index) {
        List<String> resList = new ArrayList<>();
        String value = null;
        Pattern pattern = Pattern.compile(regString);
        Matcher matcher = pattern.matcher(withinText);
        if (matcher.find()) {
            matcher.reset();
            while (matcher.find()) {
                System.out.println("匹配到的整串-->" + matcher.group(0));
                value = matcher.group(index);
                System.out.println("整串中指定的子串-->" + value);
                resList.add(value);
            }
        }
        return resList;
    }
}
